<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" isELIgnored="false" %>
<html>
<head>
    <title>全部活动</title>
    <%@ include file="static_res.jsp"%>
    <script>
        function getJoinInfo()
        {
            var uid = "${sessionScope.user.id}";
            var param = "uid="+uid;
            $.ajax({
                type : "POST",
                url : "<%=path%>/act/joinInfo",
                data : param,
                dateType : "json",
                success : function(result) {
                    var list = result;

                    $.each( JSON.parse(list), function(index, content){
                        $('#joinIn'+content).addClass("disabled");
                    });
                }


            });

            $(function() {

                $("a[id^='joinIn']").click(function(){
                    var str = ($(this).attr('id'));
                    num = parseInt(str.replace(/[^0-9]/ig,""));
                    var act_uid = $('#hidevalueuid'+num).val();
                    var act_title = $('#hidevaluetitle'+num).val();


                    var param = "actId="+num+"&actUid="+act_uid+"&actTitle="+act_title;
                    $.ajax({
                        type : "POST",
                        url : "<%=path%>/act/join",
                        data : param,
                        dateType : "text",
                        success : function(result) {
                            if ("0" == result)
                                Materialize.toast('加入失败 ！', 3000);
                            else if ("1" == result) {
                                Materialize.toast('加入成功 ！', 3000);

                            }

                        }
                    });

                    var cur = $('#cur'+num).html();
                    cur = parseInt(cur)+1;
                    $('#cur'+num).html(cur);
                    $(this).addClass("disabled");
                });
            });
        }
    </script>
</head>
<body onload="getJoinInfo()">
<%@ include file="header.jsp"%>

<div class="container">
    <div class="row"></div>
    <c:forEach items="${ActShow}" var="act">
    <div class="col s3">

            <div class="card horizontal hoverable z-depth-4">
                <div class="card-stacked">
                    <div class="card-content">
                        <p class="flow-text">${act.title}</p>
                        创建人:<a href="<%=path%>/user/visitUser?uid=${act.uid}"><span class="bold">${act.createPerson}</span></a> |
                        当前人数:<span id="cur${act.id}" class="bold">${act.currentCount}</span> |
                        最大人数:<span class="bold">${act.maxCount}</span></p>
                        <p>${act.content}</p>
                        剩余<span class="themeColor">${act.leftDay}</span>天截止
                        <input id="hidevalueuid${act.id}" type="hidden" value="${act.uid}"/>
                        <input id="hidevaluetitle${act.id}" type="hidden" value="${act.title}"/>
                    </div>
                    <div class="card-action">
                        <a id="joinIn${act.id}" class="right waves-effect waves-light btn">加入</a>
                    </div>
                </div>
            </div>

</div>
    </c:forEach>
</body>
</html>
